package database.singleDB;

import database.hset.JHashSet;
import database.keys.Key;
import database.list.JList;
import database.sortedset.JSortedSet;
import database.string.JString;
import datastruct.list.impl.JoList;

public class Router {
    public static void makeCommandTable() {
//        list 相关
        Command.registerCommand("RPush", JList::execRPush, null, Command::getFirstKey, JList::undoRPush);
        Command.registerCommand("LPush", JList::execLPush, null, Command::getFirstKey, JList::undoLPush);
        Command.registerCommand("RPop", JList::execRPop, null, Command::getFirstKey, JList::undoRPop);
        Command.registerCommand("LPop", JList::execLPop, null, Command::getFirstKey, JList::undoLPop);
        Command.registerCommand("LRange", JList::execLRange, Command::getFirstKey, null, null);
        Command.registerCommand("LIndex", JList::execLIndex, Command::getFirstKey, null, null);
        Command.registerCommand("LLen", JList::execLLen, Command::getFirstKey, null, null);
        Command.registerCommand("LInsert", JList::execLInsert, null, Command::getFirstKey, JList::undoLInsert);
        Command.registerCommand("LRem", JList::execLRem, null, Command::getFirstKey, JList::undoLRem);
        Command.registerCommand("LTrim", JList::execLTrim, null, Command::getFirstKey, JList::undoLTrim);
        Command.registerCommand("LSet", JList::execLSet, null, Command::getFirstKey, JList::undoLSet);

        // sorted set 相关
        Command.registerCommand("ZAdd", JSortedSet::execZAdd, null, Command::getFirstKey, JSortedSet::undoZAdd);
        Command.registerCommand("ZRange", JSortedSet::execZRange, Command::getFirstKey, null, null);
        Command.registerCommand("ZRem", JSortedSet::execZRem, null, Command::getFirstKey, JSortedSet::undoZRem);
        Command.registerCommand("ZCard", JSortedSet::execZCard, Command::getFirstKey, null, null);
        Command.registerCommand("ZCount", JSortedSet::execZCount, Command::getFirstKey, null, null);
        Command.registerCommand("ZRevRange", JSortedSet::execZRevRange, Command::getFirstKey, null, null);
        Command.registerCommand("ZRank", JSortedSet::execZRank, Command::getFirstKey, null, null);
        Command.registerCommand("ZRevRank", JSortedSet::execZRevRank, Command::getFirstKey, null, null);
        Command.registerCommand("ZScore", JSortedSet::execZScore, Command::getFirstKey, null, null);
        Command.registerCommand("ZDiffStore", JSortedSet::execZDiffStore, Command::getFirstKey, JSortedSet::prepareZDiffStore, JSortedSet::undoZDiffStore);
        Command.registerCommand("ZDiff", JSortedSet::execZDiff, JSortedSet::prepareZDiff, null, null);
        Command.registerCommand("ZIncrBy", JSortedSet::execZIncrBy, null, Command::getFirstKey, JSortedSet::undoZIncrBy);
        Command.registerCommand("ZUnionStore", JSortedSet::execZUnionStore, Command::getFirstKey, JSortedSet::prepareZUnionStore, JSortedSet::undoZUnionStore);
        Command.registerCommand("ZInterStore", JSortedSet::execZInterStore, Command::getFirstKey, JSortedSet::prepareZInterStore, JSortedSet::undoZInterStore);
        Command.registerCommand("ZPopMin", JSortedSet::execZPopMin, null, Command::getFirstKey, JSortedSet::undoPopMin);

        // hset 相关
        Command.registerCommand("HSet", JHashSet::execHSet, null, Command::getFirstKey, JHashSet::undoHSet);
        Command.registerCommand("HSetNX", JHashSet::execHSetNX, null, Command::getFirstKey, JHashSet::undoHSetNX);
        Command.registerCommand("HGet", JHashSet::execHGet, Command::getFirstKey, null, null);
        Command.registerCommand("HExists", JHashSet::execHExists, Command::getFirstKey, null, null);
        Command.registerCommand("HDel", JHashSet::execHDel, null, Command::getFirstKey, JHashSet::undoHDel);
        Command.registerCommand("HLen", JHashSet::execHLen, Command::getFirstKey, null, null);
        Command.registerCommand("HStrlen", JHashSet::execHStrlen, Command::getFirstKey, null, null);
        Command.registerCommand("HMSet", JHashSet::execHMSet, null, Command::getFirstKey, JHashSet::undoHMSet);
        Command.registerCommand("HMGet", JHashSet::execHMGet, Command::getFirstKey, null, null);
        Command.registerCommand("HKeys", JHashSet::execHKeys, Command::getFirstKey, null, null);
        Command.registerCommand("HVals", JHashSet::execHVals, Command::getFirstKey, null, null);
        Command.registerCommand("HGetAll", JHashSet::execHGetAll, Command::getFirstKey, null, null);
        Command.registerCommand("HIncrBy", JHashSet::execHIncrBy, null, Command::getFirstKey, JHashSet::undoHIncrBy);
        Command.registerCommand("HIncrByFloat", JHashSet::execHIncrByFloat, null, Command::getFirstKey, JHashSet::undoHIncrByFloat);
        Command.registerCommand("HRandField", JHashSet::execHRandField, Command::getFirstKey, null, null);


        // string 相关
        Command.registerCommand("Set", JString::execSet, null, Command::getFirstKey, JString::undoSet);
        Command.registerCommand("Get", JString::execGet, Command::getFirstKey, null, null);
        Command.registerCommand("MSet", JString::execMSet, null, JString::prepareMSet, JString::undoMSet);
        Command.registerCommand("MGet", JString::execMGet, JString::prepareMGet, null, null);
        Command.registerCommand("Append", JString::execAppend, null, Command::getFirstKey, JString::undoAppend);
        Command.registerCommand("Incr", JString::execIncr, null, Command::getFirstKey, JString::undoIncr);
        Command.registerCommand("IncrByFloat", JString::execIncrByFloat, null, Command::getFirstKey, JString::undoIncrByFloat);
        Command.registerCommand("IncrBy", JString::execIncrBy, null, Command::getFirstKey, JString::undoIncrBy);
        Command.registerCommand("DecrBy", JString::execDecrBy, null, Command::getFirstKey, JString::undoDecrBy);
        Command.registerCommand("Strlen", JString::execStrlen, Command::getFirstKey, null, null);
        Command.registerCommand("SetRange", JString::execSetRange, Command::getFirstKey, null, JString::undoSetRange);
        Command.registerCommand("GetRange", JString::execGetRange, Command::getFirstKey, null, null);

        // set 相关
        Command.registerCommand("SAdd", JHashSet::execSAdd, null, Command::getFirstKey, JHashSet::undoSAdd);
        Command.registerCommand("SCard", JHashSet::execSCard, Command::getFirstKey, null, null);
        Command.registerCommand("SIsMember", JHashSet::execSIsMember, Command::getFirstKey, null, null);
        Command.registerCommand("SRandMember", JHashSet::execSRandMember, Command::getFirstKey, null, null);
        Command.registerCommand("SPop", JHashSet::execSPop, null, Command::getFirstKey, JHashSet::undoSPop);
        Command.registerCommand("SRem", JHashSet::execSRem, null, Command::getFirstKey, JHashSet::undoSRem);
        Command.registerCommand("SDiff", JHashSet::execSDiff, JHashSet::prepareSDiff, null, null);
        Command.registerCommand("SUnion", JHashSet::execSUnion, JHashSet::prepareSUnion, null, null);
        Command.registerCommand("SMembers", JHashSet::execSMembers, Command::getFirstKey, null, null);

        // key 相关
        Command.registerCommand("TTL", Key::execTTL, Command::getFirstKey, null, null);
    }

}
